
using System.Collections.Generic;
using PolicyAlgebra.Util;

namespace PolicyAlgebra.Type
{
	///<summary>
	///    This class defines the actual policy. Or at least the main part of it.
	///    It represents the set of all associations between a role and permissions
	///    over an object. Although it is algibraically considered a set, it is
	///    actually implemented as a hashtable / dictionary.
	///</summary>
	///<remarks>
	/// Most of this class is a wrapper around a types dictionary since the used
	/// dictionary class is sealed. This fact is used to improve some semantics
	/// to better tune to how the algebra would like things to work (cf. the 'Add'
	/// method for instance).
	///</remarks>
	public class RoleObjectPermissionSetSetAssociationSetDict
	{ 
		private Dictionary<Role,ObjectPermissionSetSetAssociationSet> dict;

		///<summary>
		/// Constructor.
		///</summary>
		public RoleObjectPermissionSetSetAssociationSetDict()
		{
			dict = new Dictionary<Role,ObjectPermissionSetSetAssociationSet>();
		}

		public void Add(Role key, ObjectPermissionSetSetAssociationSet val)
		{
			if (dict.ContainsKey(key))
			{
				dict[key].AddMembers(val);
			} else
			{
				dict.Add(key,val);
			}
		}


		public bool ContainsKey(Role key)
		{
			return dict.ContainsKey(key);
		}


		public Dictionary<Role,ObjectPermissionSetSetAssociationSet>.KeyCollection Keys 
		{
			get
			{
				return dict.Keys;
			}
		}


		public ObjectPermissionSetSetAssociationSet this[Role key]
		{
			get
			{
				return dict[key];
			}
		}
	}
}
